package com.naiterui.ehp.bs.patient.controller;

import com.naiterui.common.repository.page.PageParamVO;
import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.context.ResourceHolder;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.security.SettingConfig;
import com.naiterui.ehp.bs.patient.service.IConsultCommentService;
import com.naiterui.ehp.bs.patient.vo.comment.CommentParamVO;
import com.naiterui.ehp.bs.patient.vo.comment.CommentVO;
import com.naiterui.ehp.bs.patient.vo.doctor.ConsultCommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 评价和投诉
 * @Author gongbaoqiang
 * @Date 2020/6/30 10:34 AM
 */
@Slf4j
@Api(tags = {SwaggerTag.PATIENT + SwaggerTag.CONSULT_COMMENT})
@RestController
@RequestMapping("ap/patient/consult/comment")
public class ApPatientConsultCommentController {

    @Autowired
    private IConsultCommentService commentService;

    @ApiOperation(value = "全部评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "医生id", required = true, dataType = "long", paramType = "query")
    })
    @PostMapping("list")
    public PageVO<ConsultCommentVO> list(Long doctorId, PageParamVO pageParamVO) throws BusinessException{
        log.info("获取医生评价：doctorId={}", doctorId);
        return commentService.findAllByDoctorId(doctorId, pageParamVO);
    }


    @ApiOperation(value = "初始化评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "医生id", required = true, dataType = "long", paramType = "query")
    })
    @PostMapping("init")
    public CommentVO getStars(Long doctorId) throws BusinessException{
        log.info("初始化评价页面：doctorId={}", doctorId);
        return commentService.init(doctorId);
    }

    @ApiOperation( value = "提交评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientId", value = "患者id", required = true, dataType = "long", paramType = "query")
    })
    @PostMapping("submit")
    public void submitComment(Long patientId, CommentParamVO paramVO) throws BusinessException{
        if (null == patientId) {
            patientId = (Long) ResourceHolder.getResource(SettingConfig.PATIENT_ID);
        }
        log.info("提交评论：patientId={}, paramVO={}", patientId, paramVO.toString());
        commentService.submit(patientId, paramVO);
    }


}
